﻿
Public MustInherit Class sentence
    Inherits iScript
    Implements iInvokeable

    Public Const separator As Char = character.semicolon

    Protected Friend Shared Function _isMeaningfulMark(ByVal c As Char) As Boolean
        Return sentenceEnd(c)
    End Function

    Public Shared Function sentenceEnd(ByVal c As Char) As Boolean
        Return c = separator
    End Function

    Private Shared Function parseImpl(ByVal input As String, ByRef index As Int64, ByRef output As sentence) As Boolean
        If value_defination.parse(input, index, output) OrElse _
           value_clause.parse(input, index, output) OrElse _
           condition.parse(input, index, output) OrElse _
           [for].parse(input, index, output) OrElse _
           [while].parse(input, index, output) OrElse _
           foreach.parse(input, index, output) OrElse _
           switch.parse(input, index, output) OrElse _
           function_call.parse(input, index, output) OrElse _
           function_call2.parse(input, index, output) OrElse _
           function_call3.parse(input, index, output) OrElse _
           function_call4.parse(input, index, output) Then
            ' OrElse comment.parse(input, index, output)
            While token(input, index, Nothing, AddressOf sentenceEnd, AddressOf [false])
            End While
            Return True
        Else
            Return False
        End If
    End Function

    Public Shared Function parse(ByVal input As String, ByRef index As Int64, ByRef output As sentence) As Boolean
        Return parsebase(input, index, output, AddressOf parseImpl)
    End Function

    Public Function invoke(ByVal ctx As context) As Boolean Implements iInvokeable.invoke
        Return invokebase(ctx)
    End Function
End Class
